<template>
  <CenterComp>
    <h1>正在加载中...</h1>
  </CenterComp>
</template>

<script>
import { mapState } from "vuex";
import CenterComp from "@/components/CenterComp";
export default {
  components: {
    CenterComp,
  },
  computed: {
    ...mapState("userStore", ["user", "isLoading"]),
  },
  methods: {
    handleLogin() {
      if (this.isLoading) {
        return;
      } else if (this.user) {
         this.$router.push({ path: this.$route.params.path });
        //  console.log("path",this.$route.params.path );
        // this.$router.push("/");
      } else {
        this.$router.push({ name: "Login" });
      }
    },
  },
  watch: {
    user: {
      //如果user有值 就调用 handler() 进入else if(this.user)
      immediate: true,
      handler() {
        this.handleLogin();
      },
    },
    isLoading: {
      //如果加载完毕 就会判断user是否有值
      immediate: true,
      handler() {
        this.handleLogin();
      },
    },
  },
};
</script>

<style>
</style>